<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/admin/AdminAction.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/Response.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/Service.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/ServiceFactory.php';

final class PostEditAction extends AdminAction {
	protected function execute(Response $response) {
		$postIdentity = null;
		if(isset($_SESSION['post-identity'])) {
			$postIdentity = $_SESSION['post-identity'];
			unset($_SESSION['post-identity']);
		}
		if(isset($_POST['identity'])) {
			$postIdentity = $_POST['identity'];
		}
		if($postIdentity !== null) {
			$serviceFactory = new ServiceFactory();
			$service = $serviceFactory->getService('PostService');
			$post = $service->read($postIdentity);
			$response->setParameter('post', $post);
		}
	}
}
?>